
module.exports = {
	methods: {
		updateMyLevel(id,level,vip_end_time){
			
			let getuserInfo = uni.getStorageSync('userInfo')
			let vipInfo ={
				vip_end_time: vip_end_time,
				level: level,
			}
			uni.setStorageSync('vipInfo', vipInfo)
			this.mNetTool.getAjaxUrlValue('capi/V2/expirationReminder/memberUser/update', {
				id: id,
				vip_end_time: vip_end_time,
				level: level,
			}, res => {
				if (res.success) {
					uni.setStorageSync('userInfo', getuserInfo)
				}
			})
		},
		getOrderList(fn) {
			var myOrderList = uni.getStorageSync("myOrderList")
			if (myOrderList) {
				typeof fn == 'function' && fn(myOrderList);
			} else {
				this.syncOrder(fn)
			}
		},
		
		syncOrder(fn) {
			 console.log('initsyncOrder')
			let getuserInfo = uni.getStorageSync('userInfo') 
			this.mNetTool.getAjaxUrlValue('capi/V2/ERorder/orderMain/list', {
				status: 100,
				user_id: getuserInfo.id, //用户id
				mobile: getuserInfo.mobile, //手机号
			}, R => {
				if (R.records > 0) {
					console.log('myOrderList',R)
					uni.setStorageSync('myOrderList', R)
				}
				typeof fn == 'function' && fn(R);
			})
		},
	},
	onShow() { 
		console.log('init里面')
 
		this.getOrderList(R=>{ 
		 
				if (R.records > 0) { 
					let getuserInfo = uni.getStorageSync('userInfo')
					getuserInfo.sale_price = R.rows[0].real_amount //会员价格
					getuserInfo.vip_end_time = R.rows[0].end_time
					getuserInfo.vip_start_time = R.rows[0].add_time
					if (R.rows[0].order_type) {
						getuserInfo.level = R.rows[0].order_type
					}
					let vipTime = new Date(R.rows[0].end_time).getTime()
					let getnowtime = new Date().getTime();
					if (getnowtime > vipTime) {
					 
						getuserInfo.level = 500
						this.updateMyLevel(getuserInfo.id,getuserInfo.level,R.rows[0].end_time);
					}
					console.log('更新后的信息',getuserInfo)
					uni.setStorageSync('userInfo', getuserInfo)
				}
		})
	},
}
